#!/usr/bin/env python
#coding=utf-8

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import json
accessKeyId="待填写"  #阿里短信KeyId
accessSecret="待填写" #阿里短信Secret
TemplateCode="SMS_210067612" #阿里短信模板code
SignName="自定义验证码" #签名名字
address="cn-hangzhou"

def Sendmesage(tel,code):
    client = AcsClient(accessKeyId, accessSecret, address)
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', address)
    request.add_query_param('PhoneNumbers',tel)
    request.add_query_param('SignName', SignName)
    request.add_query_param('TemplateCode', TemplateCode)
    data={"code":code}
    request.add_query_param('TemplateParam', json.dumps(data))
    request.add_query_param('SmsUpExtendCode', "90999")
    request.add_query_param('OutId', "abcdefgh")

    response = client.do_action(request)
    # python2:  print(response)
    print(str(response, encoding='utf-8'))
    return str(response, encoding='utf-8')

